[org 0x7c00]
KERNEL_OFFSET equ 0x1000

    mov [BOOT_DRIVE], dl;將BIOS初始化的dl傳入參數
    mov bp, 0x9000 ; set the stack
    mov sp, bp

    mov bx, MSG_REAL_MODE
    call print
    call print_nl

    call load_kernel
    call switch_to_pm
    jmp $

%include "boot/boot_sect_print.asm"
%include "boot/boot_sect_print_hex.asm"
%include "boot/boot_sect_disk.asm"
%include "boot/32bit-gdt.asm"
%include "boot/32bit-print.asm"
%include "boot/32bit-switch.asm"

[bits 16]
load_kernel:
    mov bx, MSG_LOAD_KERNEL
    call print
    call print_nl

    mov bx, KERNEL_OFFSET
    mov dh, 31
    mov dl, [BOOT_DRIVE]
    call disk_load
    ret
[bits 32]
BEGIN_PM:
    mov ebx, MSG_PRODT_MODE
    call print_string_pm

    call KERNEL_OFFSET; 調用kernel程序
    jmp $

MSG_REAL_MODE:
    db 'Started in 16-bit Real Mode', 0
MSG_PRODT_MODE:
    db 'Successfully landed in 32-bit Protected Mode', 0
MSG_LOAD_KERNEL:
    db 'Loading kernel into memory', 0

BOOT_DRIVE:
    db 0

times 510-($-$$) db 0
dw 0xaa55